﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data.Entity;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Description;
using ActiveDirectory.Models;

namespace ActiveDirectory.Controllers
{
    [Authorize]
    public class UserController : ApiController
    {
        private AdContext adContext = new AdContext();



        [ResponseType(typeof(AdUser))]
        public async Task<IHttpActionResult> GetUser()
        {
            var users = await adContext.AdUsers.ToListAsync();

            if (users == null)
            {
                return this.NotFound();
            }

            return this.Ok(users);
        }

        //[ResponseType(typeof(AdUser))]
        public async Task<IHttpActionResult> Post(UserList users)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            

            var isCorrect = await this.StoreAsync(new List<AdUser>());
            return this.Ok<bool>(isCorrect);
        }

        private async Task<bool> StoreAsync(List<AdUser> users)
        {
            //this.adContext.AdUsers.Add(answer);

            await this.adContext.SaveChangesAsync();
           // var selectedOption = await this.db.TriviaOptions.FirstOrDefaultAsync(o => o.Id == answer.OptionId
              //  && o.QuestionId == answer.QuestionId);

            return true;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.adContext.Dispose();
            }

            base.Dispose(disposing);
        }
    }

    public class UserList
    {
        public List<int> users { get; set; }
    }
}
